package com.backstage.lyorder.controller;


import com.backstage.lyorder.pojo.MobileEndOrderevaluation;
import com.backstage.lyorder.pojo.MobileEndSales;
import com.backstage.lyorder.pojo.QueryData;
import com.backstage.lyorder.service.MobileEndSalesService;
import com.backstage.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 售后表 前端控制器
 * </p>
 *
 * @author sakura
 * @since 2022-12-13
 */
@RestController
@RequestMapping("/afterSale")
@CrossOrigin
public class MobileEndSalesController {
    @Autowired
    private MobileEndSalesService afterSalesService;

    /**
     * 订单售后列表查询
     * @param queryData
     * @return
     */
    @PostMapping("list")
    public R getAfterSale(@RequestBody QueryData queryData){
        Page<MobileEndSales> page = new Page<>(queryData.getCp(), queryData.getLs());
        QueryWrapper<MobileEndSales> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(queryData.getOrderIdkw()))
            queryWrapper.eq("Mobile_end_order_orderId",queryData.getOrderIdkw());
        if (!StringUtils.isEmpty(queryData.getAftertype()))
            queryWrapper.eq("SalesType",queryData.getAftertype());
        queryWrapper.eq("status",queryData.getStatus());
        afterSalesService.page(page,queryWrapper);
        return R.ok().data("items",page.getRecords()).data("total",page.getTotal()).data("current",page.getCurrent())
                .data("pagesize",page.getSize());
    }

    /**
     * 修改售后
     * @param mobileEndSales
     * @return
     */
    @PostMapping("edit")
    public R updateAfterOrder(@RequestBody MobileEndSales mobileEndSales ){
        return afterSalesService.updateById(mobileEndSales)?R.ok():R.error();
    }


    /**
     * 根据saleid查询售后信息
     * @param SalesId
     * @return
     */
    @GetMapping("get/{SalesId}")
    public R getById(@PathVariable Long SalesId){
        MobileEndSales mobileEndSales = afterSalesService.getById(SalesId);
        if (!StringUtils.isEmpty(mobileEndSales))
            return R.ok().data("item",mobileEndSales);
        else
            return R.error();
    }

}

